package com.tarena.lbs.activity.controller;

import com.tarena.lbs.activity.pojo.param.ActivityAddParam;
import com.tarena.lbs.activity.pojo.query.ActivityQuery;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 活动相关功能接口
 */
@RestController
@Tag(name = "活动服务", description = "活动服务")
@Slf4j
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    @Operation(summary = "商家活动保存")
    @PostMapping("/admin/marketing/marketingActivity/info/save")
    public Result<Void> activitySave(@RequestBody ActivityAddParam param)
            throws BusinessException, ParseException {
        log.debug("前端-商家活动保存", param);
        activityService.insertActivity(param);
        return Result.success();
    }
    @Operation(summary = "商家活动列表")
    @PostMapping("/admin/marketing/marketingActivity/info/list")
    public Result<List<ActivityVO>> pageList()
        throws BusinessException {
        List<ActivityVO> activityList=activityService.selectList();
        return new Result<>(activityList);
    }

    @Operation(summary = "商家活动查询")
    @PostMapping("/admin/marketing/marketingActivity/info/list/qu")
    public Result<List<ActivityVO>> pageList(@RequestBody ActivityQuery query)
            throws BusinessException {
        List<ActivityVO> activityList=activityService.selectActivity(query);
        return new Result<>(activityList);
    }

    @Operation(summary = "商家活动详情")
    @GetMapping("/admin/marketing/marketingActivity/info/detail/{id}")
    public Result<ActivityVO> activityDetail(@PathVariable Integer id)
        throws BusinessException {
        log.info("前端传来的要查询的商家活动的id" +id);
        ActivityVO activity=activityService.selectByActivityId(id);
        return new Result<>(activity);
    }
    @PostMapping("/admin/marketing/marketingActivity/info/update/{id}/{status}")
    public Result<Void> updateActivityStatus(@PathVariable Integer id, @PathVariable Integer status)
        throws BusinessException {
        log.info("前端传来的要查询的商家活动的id" +id);
        log.info("前端传来的要查询的商家活动的id" +status);
        activityService.updateActivityStatus(id,status);
        return Result.success();
    }

    @PostMapping("/admin/marketing/marketingActivity/info/delete/{id}")
    public Result<Void> deleteActivity(@PathVariable Integer id)
        throws BusinessException{
        log.info("前端传来的要删除的商家活动的id" +id);
        activityService.deleteActivity(id);
        return Result.success();
    }
}
